<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text">
<input type="button" value="平方" onclick="h()">
<h1>结果：<span></span></h1>
<script>
    function h() {
        let i = document.querySelector("input");
        let s = document.querySelector("span");
        if (isNaN(i.value)){
            s.innerText = "输入错误";
            return ;
        }

        /*s.innerText = (i.value)*(i.value);*/
        //加法需要手动转换（否则自动拼接 5+5=55）
        s.innerText = parseFloat(i.value)+parseFloat(i.value);
    }
</script>
</body>
</html>